/*
 * CashTransactionDetailTests.java
 *
 *  
 */
package org.msb.finance.data;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.math.BigDecimal;

import org.junit.Before;
import org.junit.Test;

/**
 * 
 * 
 * @author boudream
 * 
 */
@SuppressWarnings("nls")
public class CashTransactionDetailTests {

	/*
	 * 
	 */
	private CashTransactionDetail ctd;

	/**
	 * @throws Exception
	 */
	@Before
	public void setUp() throws Exception {
		this.ctd = new CashTransactionDetail();
	}

	/**
	 * Test method for {@link CashTransactionDetail#setAmount(BigDecimal)}.
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetAmountInteger() throws Exception {
		final BigDecimal DECIMAL = new BigDecimal(123);

		this.ctd.setAmount(DECIMAL);
		assertEquals(DECIMAL, this.ctd.getAmount());
	}

	/**
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetAmountFloat() throws Exception {
		final BigDecimal DECIMAL = new BigDecimal(8877.6655f);

		this.ctd.setAmount(DECIMAL);
		assertEquals(DECIMAL, this.ctd.getAmount());
	}

	/**
	 * Test method for {@link TransactionDetail#setCategory(Category)}.
	 * 
	 * @throws Exception
	 */
	@Test
	public void testSetCategory() throws Exception {
		final Category c1 = new Category("Category1");
		final Category c2 = new Category("Category2");

		this.ctd.setCategory(c1);
		assertEquals(c1, this.ctd.getCategory());

		this.ctd.setCategory(c2);
		assertEquals(c2, this.ctd.getCategory());
	}

	/**
	 * Test method for {@link TransactionDetail#setIndividual(Individual)}.
	 */
	@Test
	public void testSetIndividual() {
		final Individual i1 = new Individual();
		final Individual i2 = new Individual();

		this.ctd.setIndividual(i1);
		assertEquals(i1, this.ctd.getIndividual());

		this.ctd.setIndividual(i2);
		assertEquals(i2, this.ctd.getIndividual());
	}

	/**
	 * Test method for {@link CashTransactionDetail#equals(Object)}.
	 * 
	 * @throws Exception
	 */
	@Test
	public void testEquals() throws Exception {
		assertFalse(ctd.equals(null));
		assertTrue(ctd.equals(ctd));

		final CashTransactionDetail ctd2 = new CashTransactionDetail();
		assertTrue(ctd.equals(ctd2));

		ctd2.setAmount(new BigDecimal(7.89f));
		assertFalse(ctd.equals(ctd2));

		ctd.setAmount(new BigDecimal(7.89f));
		assertTrue(ctd.equals(ctd2));

		final Category CATEGORY = new Category("ACategory");
		ctd2.setCategory(CATEGORY);
		assertFalse(ctd.equals(ctd2));

		ctd.setCategory(CATEGORY);
		assertTrue(ctd.equals(ctd2));

		final Individual INDIVIDUAL = new Individual();
		INDIVIDUAL.setFullName("Joe Smith");
		ctd2.setIndividual(INDIVIDUAL);

		assertFalse(ctd.equals(ctd2));

		ctd.setIndividual(INDIVIDUAL);
		assertTrue(ctd.equals(ctd2));

		assertFalse(ctd.equals(new Object()));
	}
}
